using Nvigorate.Aspect;
using Nvigorate.Relational.Mapping.Fluent;
using Nvigorate.Relational.State;

namespace Nvigorate.TestObjects
{
    [DatabaseLazyLoadAspect(RepositoryName = "simple")]
    [StateTrackingAspect]
    public class Vehicle : StateTracking
    {
        public string VIN { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string OwnerSocial { get; set; }
        public int ManufacturerId { get; set; }

        //public Manufacturer Manufacturer { get; set; }

        public Person Owner { get; set; }
    }

    public class VehicleMap : FluentMap<Vehicle>
    {

        //<assignment target=""VIN"" source=""vehicleId"" targetKey=""true"" sourceKey=""true"" />
        //    <assignment target=""OwnerSocial"" source=""ownerSSN"" />
        //    <assignment target=""Model"" source=""model"" />
        //    <assignment target=""Year"" source=""year"" />
        //    <assignment target=""ManufacturerId"" source=""ManufacturerId"" />

        public VehicleMap()
        {
            RepositoryName = "simple";

            var vehicleRoot = MapTable();

            vehicleRoot.Assign(v => v.VIN).AsKey().ToColumn("vehicleId");
            vehicleRoot.Assign(v => v.OwnerSocial).ToColumn("ownerSSN");
            vehicleRoot.Assign(v => v.Model);
            vehicleRoot.Assign(v => v.Year);
            vehicleRoot.Assign(v => v.ManufacturerId);

            MapParent(v => v.Owner)
                .ForeignKey(v => v.OwnerSocial, p => p.SocialSecurity);

            //MapParent(v => v.Manufacturer)
            //    .ForeignKey(v => v.ManufacturerId, m => m.Id);
        }
    }
}
